package logic

import (
	"context"
	"zhihu/models/mysql"

	"zhihu/zhihurpc/internal/svc"
	"zhihu/zhihurpc/zhihurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SpeakListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSpeakListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SpeakListLogic {
	return &SpeakListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 评论列表
func (l *SpeakListLogic) SpeakList(in *zhihurpc.SpeakListRequest) (*zhihurpc.SpeakListResponse, error) {
	// todo: add your logic here and delete this line
	var speaks []mysql.Speak
	mysql.DB.Debug().Where("problem_id = ?", in.ProblemId).Find(&speaks)

	var speakList []*zhihurpc.SpeakList
	for _, speak := range speaks {
		list := zhihurpc.SpeakList{
			UserId:  speak.UserId,
			Content: speak.Content,
		}
		speakList = append(speakList, &list)
	}

	return &zhihurpc.SpeakListResponse{
		List: speakList,
	}, nil
}
